
             
/**
 * 
 *
 * Copyright (c) 2012-2013 JLLT Corp. 2012-2013,All Rights Reserved.
 * This software is published under the 金麟龙腾商贸有限公司.
 * License version 1.0, a copy of which has been included with this
 * distribution in the LICENSE.txt file. 
 *
 * @File name:  QueryTProductByConditionAction.java   查询【商品信息:T_PRODUCT】
 * @Create on:  2012-08-01 22:13:466
 * @Author      :  高宇舟
 *
 * @ChangeList
 * ---------------------------------------------------
 * Date         Editor              ChangeReasons
 *
 */
           
        package com.boho.ecp.product.action;

            
import java.io.File;
import java.io.FileFilter;
import java.sql.Connection;
import java.util.List;

import org.apache.commons.lang.StringUtils;

import cn.boho.framework.actions.ActionImp;
import cn.boho.framework.context.ActionContext;
import cn.boho.framework.po.DynaBeanMap;
import cn.boho.framework.service.MessageService;

import com.boho.ecp.base.dao.TCategoryDao;
import com.boho.ecp.constant.Base;
import com.boho.ecp.constant.Product;
import com.boho.ecp.product.dao.TProductDao;
import com.boho.ecp.product.dao.TProductDetailDao;
import com.boho.ecp.util.MatchUtils;
public class QueryTProductByConditionAction extends ActionImp {
	private Connection con=null;
	@Override
	protected void doException(ActionContext atx, Exception ex) {
		atx.setErrorContext("EC_COMMON_1004", MessageService.getMessage("EC_COMMON_1004"),"【商品信息:T_PRODUCT|】" ,ex);
	}
	@Override
	protected int performExecute(ActionContext atx) throws Exception {
		Integer productId = null;
		try {
			productId = atx.getIntegerValue("PRODUCT_ID", -1);
		} catch (Exception e) {
			productId = -1;
		}
		DynaBeanMap dbm = TProductDao.queryTProductByCondition(con,productId);
		DynaBeanMap detailDbm = TProductDetailDao.queryTProductDetailByCondition(con, productId);
		//使用缓存//DynaBeanMap dbm=TProductCache.queryTProductByCondition(con,productId);
		if (!MatchUtils.isEmpty(dbm) && !MatchUtils.isEmpty(dbm.get("MEMBER_PRICE"))) {
			dbm.put("POINTS", Double.parseDouble(dbm.get("MEMBER_PRICE")+"")*Product.POINT_RATE);
		} else {
			return 1;
		}
		List list = TCategoryDao.queryTCategoryByCategoryID(con, Integer.parseInt(dbm.get("CATEGORY_ID")+""));
		
		atx.setValue("T_CATEGORY", list);
		atx.setValue("T_PRODUCT", dbm);
		atx.setValue("T_PRODUCT_DETAIL", detailDbm);
		return 1;
	}
	@Override
	protected int verifyParameters(ActionContext atx) throws Exception {
		con = atx.getConection();
		return 1;
	}
}
